using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

using Essentials.Persistence.Connection;
using Essentials.Persistence;

namespace Essentials.Persistence
{
    public class DataAccess
    {
        public static DataTable ExecuteDataTable(string spName)
        {        
            DbCommand dbCommand = Conn.CurrentDB.GetStoredProcCommand(spName);

            DataTable dt = Conn.CurrentDB.ExecuteDataSet(dbCommand).Tables[0];

            return dt;
        }

        public static DataTable ExecuteDataTable(string spName, DbDataParameter[] parameters)
        {
            DbCommand dbCommand = Conn.CurrentDB.GetStoredProcCommand(spName);

            foreach (DbDataParameter dbpAux in parameters)
            {
                //TODO: Todos los parametros son de entrada.
                Conn.CurrentDB.AddInParameter(dbCommand, dbpAux.ParameterName, dbpAux.DbType, dbpAux.ParameterValue);
            }

            DataTable dt = Conn.CurrentDB.ExecuteDataSet(dbCommand).Tables[0];

            return dt;
        }

        public static DbDataParameter DataParameter(string parameterName, System.Data.DbType dbType, object parameterValue, System.Data.ParameterDirection direction)
        {
            return new DbDataParameter(parameterName, dbType, parameterValue, direction);
        }     

    }
}
